#include <stdio.h>
#include <yawl.h>

class ChildForm: public TEventWindow {
	TListBox *lb;
	TFrameWindow* m_parent;
public:
    void show_lb(int code)
    {
		if (code == 2) {
		  char buff[80];
		  sprintf(buff,"%d",lb->selected());
		  set_text(buff);
		  m_parent->set_focus();
		}
    }

	ChildForm(char *caption, TFrameWindow* f) : TEventWindow(caption),m_parent(f)
	{
 	 Layout(this) << Listbox(150,(EH)show_lb) << NamedAs(&lb);
	 lb->add("one");
	 lb->add("two");
	 lb->add("three");
	 lb->selected(0);

    }
};


class MyWin: public TFrameWindow {
public:

  float a,b,c,q;
  double d;
  int k,n;
  bool bFirst,bSecond,bThird;
  char name[80];
  TListBox *lb;
  TTrackBar *tb;
  TEdit *alpha_edit;

  void get_values(int id)
  {
   update_data();
   d = a + b + c;
   a *= 2;
   b *= 2;
   c *= 2;  
   //k++;
   update_controls();
  }

  void close(int)
  {
    destroy();
  }

  void show_lb(int idx)
  {
	  k ++;	  
	  lb->add("yeah!");
	  update_controls();
	  alpha_edit->set_text(name);
   }

  void set_edit(int)
  {
	  alpha_edit->set_text("yay!");
  }

  void open_form(int)
  {
	  ChildForm *form = new ChildForm("A Child Form",this);
	  form->show();
  }

  void on_track(int)
  {
    k = tb->pos();
	update_controls();
  } 

  MyWin()
      : TFrameWindow("A Simple Layout", false)
  {	 
	 a = 1; b = 2; c = 3;  d = 3.131; q = 3;
	 k = 1; n = 10;

	 bFirst = true;
	 bSecond = false;
	 bThird = true;

	 tb = new TTrackBar(this,999);
	 tb->resize(0,0,90,20);
	 tb->range(0,10);
	 tb->pos(0);

	 Layout(this)
		 << Field("Alpha",a) << NamedAs(&alpha_edit)
		 << Field("Beta",b)
		 << Field("Gamma",c)
		 << Field("Delta",d)
		 << Field("Count",k)
		 << Listbox(150,name,(EH)show_lb) << NamedAs(&lb) << Next
		 << (GroupBox("Options",this)
		    << Checkbox("First",bFirst)
		    << Checkbox("Second",bSecond)
			<< Checkbox("Third",bThird)
			<< End
			) << Next
         << Control(tb,(EH)on_track)  << Next << Next
		 << Button("Go!",(EH)get_values)
		 << Button("Close",(EH)close)
		 << Next
		 << Button("whatever",(EH)set_edit)
		 << Button("open!",(EH)open_form)
		 << End
     ;
	 lb->add("one");
	 lb->add("two");
	 lb->add("three");
	 lb->selected(0);
	
  }
};

MyWin* w;

int main(int,char **) 
{
 w = new MyWin();
 w->show();
 w->run();
 delete w;
 return 0;
}
